﻿@model ALinq.BBS.DataAccess.ReplyList
@using ALinq.BBS.DataAccess
@using ALinq.BBS
@using ALinq.BBS.Models
@using ALinq.BBS.App_GlobalResources
@{
    var post = (Post)ViewBag.Post;
    var forum = (Forum)ViewBag.Forum;
    var board = (Board)ViewBag.Board;
    var replyList = (ReplyList)Model;
    var postListIndex = (int)ViewBag.PostListIndex;
    var replyListIndex = replyList.Index;

    var returnUrl = Request.QueryString["returnUrl"];

    Layout = "_Layout.cshtml";
    PageData["Title"] = post.Title;
    PageData["Css"] = "Post.css";

    PageData["Scripts"] = new[]{ "/Scripts/syntaxhighlighter/scripts/shCore.js",
                            "/Scripts/syntaxhighlighter/scripts/shBrushCSharp.js",
                            "/Scripts/syntaxhighlighter/scripts/shBrushVb.js"};

    PageData["Styles"] = new[] { "/Scripts/syntaxhighlighter/styles/shCoreDefault.css" };

    IEnumerable<IArticle> articles = new IArticle[] { post }.Union(replyList);

    Func<int, string> createUrl = delegate(int pageIndex)
    {
        var obj = new { boardID = board.ID, postID = post.ID, replyListIndex = pageIndex };
        return Url.RouteUrl(RouteNames.PostList, obj);
    };

    var pagesCount = post.Replies.PagesCount;
    pagesCount = pagesCount == 0 ? 1 : pagesCount;
    var pagingModel = new PagingModel(post.Replies.Count + 1, pagesCount, replyList.Index, createUrl);

    var navigateForums = new Stack<Forum>();
    var p = forum;
    while (p != null)
    {
        navigateForums.Push(p);
        p = p.Parent;
    }

    //按下 ID 排序
    Post previousPost = forum.Posts.OrderBy(o => o.ID)
                                   .Where(o => o.ID > post.ID).FirstOrDefault();
    Post nextPost = forum.Posts.OrderByDescending(o => o.ID)
                               .Where(o => o.ID < post.ID).FirstOrDefault();
}
<script type="text/javascript">    SyntaxHighlighter.all();</script>
<div style="margin-bottom: 10px; float: left;">
    @Html.ActionLink("Forum", "Index")
    <span>> </span>
    @foreach (var item in navigateForums)
    {
        var pageIndex = 0;
        if (item == forum)
        {
            pageIndex = postListIndex;
        }
        @Html.RouteLink(item.Name, RouteNames.PostList, new { boardID = board.ID, forumID = forum.ID, pageIndex });
        <span>> </span>
    }
    <span style="font-size: 12px; font-weight: bold">@Label.TopicContent</span>
</div>
@if (returnUrl != null)
{
    <div style="margin-bottom: 10px; float: right">
        <a href="@Request.QueryString["returnUrl"]" title="@Label.Return">
            <img src="@Url.Content("~/Content/Images/Button/return.gif")" alt="@Label.Return"  />
        </a>
    </div>
}
<div class="HackBox">
</div>
<div style="float: left; margin-bottom: 8px;">
    <img src="@this.ArticleIcon(post)" alt="PostType" />
    <a style="font-size: 14px; font-weight: bold;" href="@Url.RouteUrl(RouteNames.Post, new { boardID = board.ID, forumID = forum.ID, postID = post.ID })">
        @post.Title</a>
</div>
<div style="float: right; margin-top: 6px;">
    @if (nextPost != null)
    {
        var args = new { boardID = board.ID, forumID = forum.ID, postID = nextPost.ID, returnUrl = returnUrl };
        var atts = new { title = nextPost.Title };
        @Html.RouteLink(Label.NextTopic, RouteNames.Post, args, atts);
    }
    <span></span>
    @if (previousPost != null)
    {
        var args = new { boardID = board.ID, forumID = forum.ID, postID = previousPost.ID, returnUrl = returnUrl };
        var atts = new { title = previousPost.Title };
        @Html.RouteLink(Label.PreviousTopic, RouteNames.Post, args, atts);
    }
</div>
<div class="HackBox">
</div>
<div style="float: left;">
    <a href="#content">
        <img src="@Url.Content("~/Content/Images/Button/QuickReply.gif")" alt="快速回复"/>
    </a><a href="@Url.RouteUrl(RouteNames.EditReply, new { boardID = board.ID, forumID = forum.ID, postListIndex = postListIndex, postID = post.ID, replyListIndex = 0 })">
        <img src="@Url.Content("~/Content/Images/Button/NewReply.gif")" alt="发表回复" />
    </a>
</div>
<div style="float: right; margin-top: 8px;">
    @RenderPage("../Shared/Controls/PagingBar.cshtml", pagingModel)
</div>
<div class="HackBox">
</div>
@foreach (var article in articles)
{
    var user = article.User;
    string editUrl;
    string deleteUrl;
    if (article is Reply)
    {
        var obj = new
        {
            boardID = board.ID,
            forumID = forum.ID,
            postListIndex = postListIndex,
            postID = post.ID,
            replyListIndex = replyListIndex,
            replyID = ((Reply)article).ID
        };
        editUrl = Url.RouteUrl(RouteNames.EditReply, obj);
        deleteUrl = Url.RouteUrl(RouteNames.DeleteReply, obj);
    }
    else
    {
        var obj = new { boardID = board.ID, forumID = forum.ID, postListIndex = postListIndex, postID = post.ID };
        editUrl = Url.RouteUrl(RouteNames.EditPost, obj);
        deleteUrl = Url.RouteUrl(RouteNames.DeletePost, obj);
    }
    <div class="replyTop">
        <img src="@this.ArticleIcon(post)" alt="PostType" />
        @article.Title
    </div>
    <table style="width: 100%" border="0" cellspacing="0" cellpadding="0" id="">
        <tr align="left">
            <td rowspan="4" class="userInfo">
                <div style="width: 140px;">
                    <div class="userItem" style="text-align: center">
                        <img alt="" src="@Url.Content("~/Content/UserPhotos/1.gif")" />
                    </div>
                    <div class="userItem" style="width: 100%; text-align: center;">
                        <div style="float: left; width: 80px; text-align: left;">
                        </div>
                        <div style="float: left; text-align: left; width: 80px;">
                        </div>
                        @*<div style="float: left; width: 60px; text-align: left;">
                                </div>
                                <div style="float: left; text-align: left; width: 60px;">
                                </div>*@
                        <table style="font-size: 12px">
                            <tr>
                                <td style="text-align: right; width: 60px;">
                                    <b>@Label.UserName:</b>
                                </td>
                                <td style="text-align: left">
                                    @user.Name
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: right;">
                                    @Label.Posts:
                                </td>
                                <td style="text-align: left">
                                    @user.PostsCount
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: right">
                                    @Label.Join:
                                </td>
                                <td style="text-align: left">
                                    @user.CreationDate.ToShortDateString()
                                </td>
                            </tr>
                        </table>
                    </div>
                    @*<div id="ctrQQ" class="userItem" style="margin-bottom: 6px;" runat="server">
                                <a target="_blank" href="http://wpa.qq.com/msgrd?V=1&Menu=yes&Uin=">
                                    <img src="http://wpa.qq.com/pa?p=1::6" />
                                </a>
                            </div> *@
                </div>
            </td>
            <td class="replyTitle">
                <div style="float: left; margin: 8px 0px 0px 10px;">
                    字体大小:
                </div>
                <div class="fontSizeButton" onclick="Larger($(this).up(1).next().down())">
                    大
                </div>
                <div class="fontSizeButton" onclick="Smaller($(this).up(1).next().down())">
                    小
                </div>
                <div style="float: right; margin-top: 6px; margin-right: 4px;">
                    <img src="@Url.Content("~/Content/Images/Button/Favor.gif")" alt="Favor" />
                    <a href="@editUrl">
                        <img src="@Url.Content("~/Content/Images/Button/Edit.gif")" alt="Edit" /></a>
                    <a href="@deleteUrl">
                        <img src="@Url.Content("~/Content/Images/Button/Delete.gif")" alt="Delete" />
                    </a>
                    <img src="@Url.Content("~/Content/Images/Button/Quote.gif")" alt="Quote" />
                </div>
                <div class="HackBox">
                </div>
            </td>
        </tr>
        <tr align="left">
            <td valign="top" class="replyContent" style="padding: 20px 20px 20px 20px; height: 200">
                @*<div><asp:PlaceHolder ID="ctrTop" runat="server"></asp:PlaceHolder>
                    </div>
                    <div>
                        <asp:PlaceHolder ID="ctrMain" runat="server"></asp:PlaceHolder>
                    </div>
                    <div>
                        <asp:PlaceHolder ID="ctrBottom" runat="server"></asp:PlaceHolder>
                    </div>*@
                <div>
                    @Html.Raw(article.Content)
                </div>
                <div style="margin-top: 50px; text-align: right;">
                    @*<a href="<%#PostListPage.CreateUrl((int)Eval("BoardID")) %>">
                                <asp:Image ID="imgReturn" src="Button/return.gif" alt="??" runat="server" />
                            </a><a href="#header">
                                <asp:Image ID="imgTop" src="Button/top.gif" alt="??" runat="server" />
                            </a>*@
                </div>
            </td>
        </tr>
        <tr align="left">
            <td class="userSign">
                <div style="margin-bottom: 6px;">
                    <a target="_blank">
                        <img alt="???" src="" style="border: 0px;" />
                    </a>
                </div>
                <div>
                    <a target="_blank" href=""></a>
                </div>
            </td>
        </tr>
    </table>
}
<div class="replyTop">
</div>
